package org.csu.group4.jpetstore.persistence;

import org.apache.ibatis.annotations.*;
import org.csu.group4.jpetstore.mybatis.entity.ShopCart;
import org.springframework.stereotype.Component;

import java.util.List;

@Mapper
@Component
public interface ShopCartDAO {
    @Select("select id, item_id as itemId, account_id as accountId, quantity, status from shopcart where account_id=#{username} and status=200")
    List<ShopCart> getAllByUsername(String username);

    @Select("select * from shopcart where status = 203")
    List<ShopCart> getAll();

    @Insert("insert into shopcart(id, item_id, account_id, quantity) values (#{id},#{itemId}, #{accountId}, #{quantity})")
    void insertNewItem(ShopCart shopCart);

    @Update("UPDATE shopcart SET quantity=#{quantity}, status=#{status}  where id =#{id}")
    void updateItem(ShopCart shopCart);

    @Update("UPDATE shopcart SET status=#{status} where item_id=#{itemId} and account_id = #{accountId}")
    void updateStatus(ShopCart shopCart);

    @Select("SELECT id, item_id as itemId, account_id as accountId, quantity, status from shopcart where account_id=#{username} and status=200 and item_Id = #{itemId}")
    ShopCart getAllByUsernameAndItemId(@Param("username") String username,@Param("itemId") String itemId);

}
